package ltd.qisi.autoguipilot


import android.animation.Animator
import android.content.Intent
import android.graphics.PixelFormat
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.Gravity
import android.view.View
import android.view.WindowManager
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import com.airbnb.lottie.LottieAnimationView
import ltd.qisi.autoguipilot.R


class MainActivity : AppCompatActivity() {
    private lateinit var rippleAnimation: LottieAnimationView
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        rippleAnimation = findViewById(R.id.rippleAnimation)
        findViewById<Button>(R.id.btn).setOnClickListener {
            playRippleEffect()
        }
    }

    private fun playRippleEffect() {
        val intent = Intent(this,BridgeService::class.java)
        intent.action = "ACTION_SHOW_RIPPLE"
        intent.putExtra("x",500)
        intent.putExtra("y",500)
        startForegroundService(intent)
    }

//    private fun showFloatingWindow() {
//        // 创建悬浮窗视图
//        val floatingView: View = layoutInflater.inflate(R.layout.layout_floating_window, null)
//        val rippleAnimation: LottieAnimationView = floatingView.findViewById(R.id.rippleAnimation)
//
//        rippleAnimation.progress = 0f
//        rippleAnimation.playAnimation()
//        rippleAnimation.setMaxProgress(0.25f)
//
//        rippleAnimation.addAnimatorListener(object : Animator.AnimatorListener{
//            override fun onAnimationStart(animation: Animator) {
//                Log.i("wangzhenghui","onAnimationStart")
//            }
//
//            override fun onAnimationEnd(animation: Animator) {
//                Log.i("wangzhenghui","onAnimationEnd")
//                windowManager.removeView(floatingView)
//            }
//
//            override fun onAnimationCancel(animation: Animator) {
//                Log.i("wangzhenghui","onAnimationCancel")
//            }
//
//            override fun onAnimationRepeat(animation: Animator) {
//                Log.i("wangzhenghui","onAnimationRepeat")
//            }
//
//        })
//        // 设置悬浮窗参数
//        val params = WindowManager.LayoutParams(
//            WindowManager.LayoutParams.WRAP_CONTENT,
//            WindowManager.LayoutParams.WRAP_CONTENT,
//            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY else WindowManager.LayoutParams.TYPE_PHONE,
//            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
//            PixelFormat.TRANSLUCENT
//        )
//
//        params.gravity = Gravity.TOP or Gravity.START
//        params.x = 0
//        params.y = 100
//
//        // 获取WindowManager并添加视图
//        val windowManager = getSystemService(WINDOW_SERVICE) as WindowManager
//        windowManager.addView(floatingView, params)
//
//    }
}